home *** CD-ROM | disk | FTP | other *** search
/ Singles Flirt Up Your Life! (German) / Singles Flirt Up Your Life.iso / data1.cab / Statemachine / sofa.lua < prev    next >
Text File  |  2004-01-29  |  5KB  |  147 lines

  1. -- sofa state machine
  2.  
  3. beginStateMachine()
  4.  
  5.     onMsg("buildMenu", function(msg)
  6.     
  7.         if (repairMenu()) then return end
  8.         
  9.         -- build the pie menu
  10.         clearPieMenu();
  11.         local button ;
  12.  
  13.         button = addPieMenuButton("pm_sleepSofa", "nap");
  14.         button.addDescription(ACTIVITY, "nap");
  15.         
  16.         button = addPieMenuButton("pm_sitdown", "sit");
  17.         button.addDescription(ACTIVITY, "sit");
  18.         
  19.         local character = getStateObjectFromID(msg.sender);
  20.         
  21.         if (not isUser(character, this, {"sit"})) then    
  22.             local otherUsers = getOtherUsers(character, this, "sit")
  23.             if (getn(otherUsers) > 0) then
  24.                 local characterOnSofa = otherUsers[1];
  25.                 if activityPossible(character, "kissIntimate", characterOnSofa) then
  26.                     button = addPieMenuButton("pm_getIntimateSofa", "getIntimateSofa");
  27.                     button.addDescription(ACTIVITY, "kissIntimate");
  28.                 else
  29.                     print("activityPossible failed");
  30.                 end;
  31.             else
  32.                 print("nobody on sofa");
  33.             end
  34.         else
  35.             print("sender is user");
  36.         end
  37.         
  38.     end )
  39.     
  40.     -- sit on sofa
  41.     onMsg("sit", function(msg)
  42.         -- get the game object server
  43.         local gameObjectServer = getGameObjectServer();
  44.         -- get character who initiated this action
  45.         local character = getStateObjectFromID(msg.sender);
  46.         -- if this is broken: abort characters action
  47.         if abortIfBroken(character) then return end;        
  48.         -- walk to the closest action point
  49.         local actionPoint = character.getClosestFreeActionPointToClickPoint(this, {"sit1", "sit2", "sit3"});
  50.         if (actionPoint) then 
  51.         
  52.             local wso = character.walkSO;
  53.             -- create state machine contexts
  54.             local wsoContext = StateMachineContext();
  55.             -- store the action point
  56.             wsoContext.storeData("actionPointName", actionPoint.getName());
  57.             if (wso.walkToActionPoint(actionPoint)) then
  58.                 wso.queueStateMachine("sofaChar.sitDown", this, wsoContext);
  59.             else
  60.                 print("no path found");
  61.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  62.             end
  63.         else
  64.             print("no action point found");
  65.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  66.         end
  67.     end )
  68.     
  69.     -- lay on sofa
  70.     onMsg("nap", function(msg)
  71.         -- get the game object server
  72.         local gameObjectServer = getGameObjectServer();
  73.         -- get the current character
  74.         local character = getStateObjectFromID(msg.sender);
  75.         -- if this is broken: abort characters action
  76.         if abortIfBroken(character) then return end;        
  77.         -- walk to the action point
  78.         local actionPoint = character.getFreeActionPoint(this, "sit2");
  79.         if (actionPoint) then
  80.             -- get the walk state object
  81.             local wso = character.walkSO;
  82.             local wso = character.walkSO;
  83.             -- create state machine contexts
  84.             local wsoContext = StateMachineContext();
  85.             -- store the action point
  86.             wsoContext.storeData("actionPointName", actionPoint.getName());
  87.             if (wso.walkToActionPoint(actionPoint)) then
  88.                 wso.queueStateMachine("sofaChar.layDown", this, wsoContext);
  89.             else
  90.                 print("no path found");
  91.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  92.             end
  93.         else
  94.             print("no action point found");
  95.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  96.         end
  97.     end )
  98.     
  99.     
  100.     -- get intimate with a sofa occupant
  101.     onMsg("getIntimateSofa", function(msg)
  102.         local character = getStateObjectFromID(msg.sender);
  103.         local occupants = getOtherUsers(character, this, "sit")
  104.         
  105.         if (getn(occupants) == 0) then 
  106.             print("doublebed.lua::getIntimateBed no occupants found");
  107.             instantAbort(character, EMOTICON_CANNOT, "emoThink");
  108.             return
  109.         end
  110.         
  111.         local occupant = occupants[1];
  112.         character.sendMsg("getIntimateSofa", occupant);
  113.         
  114.     end )
  115.     
  116.     
  117.     
  118.     -- repair
  119.     onMsg("repair", function(msg)
  120.     
  121.         print("onMsg repair");
  122.         -- get character who initiated this action
  123.         local character = getStateObjectFromID(msg.sender);
  124.         -- walk to the closest action point
  125.         local actionPoint = character.getFreeActionPoint(this, "repair");
  126.         -- get the walk state object
  127.         local wso = character.walkSO;
  128.         if (actionPoint) then
  129.             -- create state machine contexts
  130.             local wsoContext = StateMachineContext();
  131.             -- store the action point
  132.             wsoContext.storeData("actionPointName", actionPoint.getName());
  133.             if (wso.walkToActionPoint(actionPoint)) then
  134.                 wso.queueStateMachine("repairChar.repairStart", this, wsoContext);
  135.             else
  136.                 print("no path found");
  137.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  138.             end
  139.         else
  140.             print("no action point found");
  141.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  142.         end
  143.     end )
  144.     
  145.             
  146. endStateMachine()
  147.